import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
const store = new Vuex.Store({
    state: {
        userInfo:uni.getStorageSync("userInfo") || {}
    },
    getters: {
        userInfo: state => state.userInfo
    },
    mutations: {
        payload(state, action) {
            if (action.type) {
                state[action.type] = action.value;
            } else {
                for (let type in action) {
                    state[type] = action[type];
                }
            }
        }
    },
    actions: {
        setUserInfo({ commit }, data){
            commit('payload', {
                type: 'userInfo',
                value: data
            })
            uni.setStorageSync('userInfo', data);
        }
    },
    modules: {}
})
export default store
